package com.cty.tree;
/*
*
* 测试二叉树
*
*
* */
public class BinaryTreeDemo {
    public static void main(String[] args) {
        //测试一下（手动加入）
        HeroNode root = new HeroNode(1,"宋江");
        HeroNode heroNode2 = new HeroNode(2,"吴用");
        HeroNode heroNode3 = new HeroNode(3,"卢俊义");
        HeroNode heroNode4 = new HeroNode(4,"林冲");
        HeroNode heroNode5 = new HeroNode(5,"关胜");
        root.left = heroNode2;
        root.right = heroNode3;
        heroNode3.right = heroNode4;
        heroNode3.left = heroNode5;
        BinaryTree binaryTree = new BinaryTree(root);
        binaryTree.preOrder();
        binaryTree.midOrder();
        binaryTree.postOrder();
        //测试前序序查找
        HeroNode resNode = null;
        resNode = root.preOrderSearch(5);
        if (resNode != null) {
            System.out.printf("目标节点: id:%s,name:%s\n",resNode.id,resNode.name);
        } else {
            System.out.println("没有找到目标节点");
        }

        //测试一下中序查找
        resNode = null;
        resNode = root.midOrderSearch(5);
        if (resNode != null) {
            System.out.printf("目标节点: id:%s,name:%s\n",resNode.id,resNode.name);
        } else {
            System.out.println("没有找到目标节点");
        }

        //测试一下后序查找
        resNode = null;
        resNode = root.postOrderSearch(5);
        if (resNode != null) {
            System.out.printf("目标节点: id:%s,name:%s\n",resNode.id,resNode.name);
        } else {
            System.out.println("没有找到目标节点");
        }
        binaryTree.delNode(3);
        binaryTree.preOrder();
    }
}
